@echo off
chcp 65001 > nul

echo 构建PDF测试程序...
echo ========================================

cd /d "D:\Codes\longimagereader"

if not exist "build_test" mkdir build_test
cd build_test

echo 运行CMake配置...
copy "..\CMakeLists_test.txt" "CMakeLists.txt"
"C:\Qt\Tools\CMake_64\bin\cmake.exe" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..

if %ERRORLEVEL% NEQ 0 (
    echo CMake配置失败！
    pause
    exit /b 1
)

echo 开始编译...
mingw32-make

if %ERRORLEVEL% NEQ 0 (
    echo 编译失败！
    pause
    exit /b 1
)

echo.
echo 构建完成！可执行文件：PDFTestViewer.exe
echo ========================================

echo 复制必要的DLL文件...
if exist "..\mingw64-poppler\bin\*.dll" (
    copy "..\mingw64-poppler\bin\*.dll" .
)

echo 运行Qt部署工具...
"C:\Qt\6.9.2\mingw_64\bin\windeployqt.exe" --release --no-translations PDFTestViewer.exe

echo.
echo 测试程序准备就绪！
echo 运行: build_test\PDFTestViewer.exe
pause